# #!/usr/bin/env python
# # -*- encoding: utf-8 -*-
# '''@File    :   PhysicalLayer_BusProtocol_test.py
# @Time    :   2025/06/15 10:00:00
# @Author  :   YangLiang
# @Version :   1.0
# @Contact :   yangl@genvict.com
# @License :   (C)Copyright 2022-2025
# @Desc    :   UDS物理层和总线协议测试用例，包括单帧/多帧传输、流控参数、错误处理等测试场景'''

# from pytest_assume.plugin import assume
# import pytest
# import logging
# import time
# from commDriver.TS_CAN import *
# import allure
# import sys
# sys.dont_write_bytecode = True

# # 物理层单帧传输测试用例 (正常情况)
# single_frame_normal = [
#     ("单帧正响应测试", "22 F1 86", "62 F1 86 01", 1),          # 默认会话读取数据标识符
#     ("单帧抑制响应测试", "22 F1 86 80", "", 3),               # 扩展会话抑制响应
#     ("编程会话单帧测试", "2E F1 86 02", "6E F1 86", 2),        # 编程会话写入数据
#     ("最大长度单帧测试", "22 F1 C0" + "00"*7, "62 F1 C0" + "00"*7, 3),  # 扩展会话最大长度(8字节)
#     ("最小长度单帧测试", "19 01", "59 01 00", 1),               # 默认会话最小长度(1字节)
#     ("功能寻址单帧广播", "3E 80", "", 3)                       # 扩展会话功能寻址广播
# ]

# # 传输层多帧传输测试用例
# transport_multi_frame = [
#     ("多帧请求测试(16字节)", "31 01 00 10 00 01 02 03 04 05 06 07 08 09 0A 0B", "71 01", 3),  # 扩展会话长数据传输
#     ("多帧响应测试(24字节)", "22 F1 90", "62 F1 90 00 18 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12", 1),  # 默认会话长响应
#     ("编程会话多帧测试(32字节)", "34 00 00 00 00 20" + "00"*32, "74 00", 2),  # 编程会话最大长度传输
#     ("多帧分段边界测试(8字节)", "2E F1 A0" + "01"*8, "6E F1 A0", 3),  # 扩展会话刚好分段边界
#     ("默认会话多帧抑制响应", "22 F1 B0 80" + "00"*16, "", 1),  # 默认会话抑制多帧响应
#     ("多帧特殊数据测试(全FF)", "31 03 00 10" + "FF"*16, "71 03", 3),  # 扩展会话全FF数据
#     ("多帧交替数据测试", "31 04 00 10" + "00FF"*8, "71 04", 3)  # 扩展会话交替数据
# ]

# # 流控参数测试用例 (FS=0x00:继续发送, BS=0x05:块大小, STmin=0x0A:间隔10ms)
# flow_control_tests = [
#     ("流控参数BS=5测试", "36 00 01 02 03 04 05 06", "30 00 05 0A", 2),  # 编程会话块大小5
#     ("流控参数STmin=0测试", "36 00 0A 0B 0C 0D 0E 0F", "30 00 00 00", 3),  # 扩展会话无间隔
#     ("流控参数FS=1测试(等待)", "36 00 10 11 12 13 14 15", "30 01 03 05", 3),   # 扩展会话等待流控
#     ("流控参数BS=0测试(无限制)", "36 00 20 21 22 23 24 25", "30 00 00 0A", 3),  # 扩展会话块大小无限制
#     ("流控参数STmin=10测试", "36 00 30 31 32 33 34 35", "30 00 05 0A", 2),  # 编程会话间隔10ms
#     ("流控参数FS=2测试(停止)", "36 00 40 41 42 43 44 45", "30 02 05 0A", 3),    # 扩展会话停止发送
#     ("默认会话流控参数测试", "36 00 60 61 62 63 64 65", "30 00 03 0A", 1)     # 默认会话流控配置
# ]

# # 传输层错误处理测试用例
# transport_error_cases = [
#     ("无效帧类型测试", "AA 00 01 02 03 04 05 06", "7F AA 13", 1),          # 未知帧类型NRC13
#     ("连续帧序号错误", "23 02 07 08 09 0A 0B 0C", "7F 23 24", 3),          # 序列错误NRC24
#     ("超出最大数据长度", "31 05 00 40" + "00"*50, "7F 31 31", 2),          # 传输层错误NRC31
#     ("流控超时测试", "10 03", "7F 10 25", 1),                               # 超时NRC25
#     ("无效STmin值测试", "36 00 50 51 52 53 54 55", "7F 36 31", 3),          # 无效STmin值NRC31
#     ("连续帧数据长度错误", "23 01 00 01 02 03 04 05 06", "7F 23 13", 1),    # 数据长度错误NRC13
#     ("多帧传输丢失帧测试", "31 02 00 20" + "00"*20, "7F 31 25", 3),         # 帧丢失超时NRC25
#     ("编程会话帧丢失测试", "34 00 00 00 00 10" + "00"*16, "7F 34 25", 2),   # 编程会话帧丢失超时
#     ("重复连续帧序号测试", "23 01 0A 0B 0C 0D 0E 0F", "7F 23 24", 3),         # 重复序列错误NRC24
#     ("功能寻址编程会话测试", "34 00 00 00 00 08" + "00"*8, "7F 34 7E", 2),   # 编程会话功能寻址NRC7E
#     ("请求序列错误测试", "23 01 00 01 02 03 04 05", "7F 23 78", 1)          # 请求序列错误NRC78
# ]

# '''物理寻址物理层和总线协议测试用例'''
# class Test_UDS_PhysicalLayer_Phy(object):
    
#     @allure.severity('normal')
#     @allure.story('物理层单帧传输')
#     @allure.title('{case_name} - 物理寻址')
#     @allure.description('验证物理寻址模式下不同会话的单帧传输功能，包括正响应和抑制响应场景')
#     @pytest.mark.parametrize('case_name, req, resp, session', single_frame_normal, 
#                             ids=[case[0] for case in single_frame_normal])
#     def test_single_frame_transfer_Phy(self, action, Driver, case_name, req, resp, session):
#         """
#         物理寻址单帧传输测试
#         :param action: 测试动作对象
#         :param Driver: CAN驱动对象
#         :param case_name: 测试用例名称
#         :param req: 请求报文
#         :param resp: 预期响应报文
#         :param session: 会话类型(1:默认, 2:编程, 3:扩展)
#         """
#         iStep = 1
#         iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, session, iStep, False)

#     @allure.severity('critical')
#     @allure.story('传输层多帧传输')
#     @allure.title('{case_name} - 物理寻址')
#     @allure.description('验证物理寻址模式下多帧数据传输功能，包括长请求和长响应处理')
#     @pytest.mark.parametrize('case_name, req, resp, session', transport_multi_frame, 
#                             ids=[case[0] for case in transport_multi_frame])
#     def test_multi_frame_transfer_Phy(self, action, Driver, case_name, req, resp, session):
#         """
#         物理寻址多帧传输测试
#         :param action: 测试动作对象
#         :param Driver: CAN驱动对象
#         :param case_name: 测试用例名称
#         :param req: 请求报文
#         :param resp: 预期响应报文
#         :param session: 会话类型(1:默认, 2:编程, 3:扩展)
#         """
#         iStep = 1
#         # 设置较长的超时时间(多帧传输需要)
#         iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, session, iStep, False, timeout=2000)

#     @allure.severity('normal')
#     @allure.story('传输层流控参数')
#     @allure.title('{case_name} - 物理寻址')
#     @allure.description('验证物理寻址模式下流控参数(FS/BS/STmin)的配置和响应')
#     @pytest.mark.parametrize('case_name, req, resp, session', flow_control_tests, 
#                             ids=[case[0] for case in flow_control_tests])
#     def test_flow_control_parameters_Phy(self, action, Driver, case_name, req, resp, session):
#         """
#         物理寻址流控参数测试
#         :param action: 测试动作对象
#         :param Driver: CAN驱动对象
#         :param case_name: 测试用例名称
#         :param req: 请求报文
#         :param resp: 预期响应报文
#         :param session: 会话类型(1:默认, 2:编程, 3:扩展)
#         """
#         iStep = 1
#         iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "3E 00", "7E 00", session, iStep, True)
#         Driver['CAN'].sendFrame

#     @allure.severity('normal')
#     @allure.story('传输层错误处理')
#     @allure.title('{case_name} - 物理寻址')
#     @allure.description('验证物理寻址模式下传输层错误处理机制，包括无效帧、序号错误和超时等场景')
#     @pytest.mark.parametrize('case_name, req, resp, session', transport_error_cases, 
#                             ids=[case[0] for case in transport_error_cases])
#     def test_transport_error_handling_Phy(self, action, Driver, case_name, req, resp, session):
#         """
#         物理寻址传输层错误处理测试
#         :param action: 测试动作对象
#         :param Driver: CAN驱动对象
#         :param case_name: 测试用例名称
#         :param req: 请求报文
#         :param resp: 预期响应报文
#         :param session: 会话类型(1:默认, 2:编程, 3:扩展)
#         """
#         iStep = 1
#         iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, session, iStep, False)


# '''功能寻址物理层和总线协议测试用例'''
# class Test_UDS_PhysicalLayer_Func(object):
    
#     @allure.severity('normal')
#     @allure.story('功能寻址单帧传输')
#     @allure.title('{case_name} - 功能寻址')
#     @allure.description('验证功能寻址模式下不同会话的单帧传输功能，包括正响应和抑制响应场景')
#     @pytest.mark.parametrize('case_name, req, resp, session', single_frame_normal, 
#                             ids=[case[0] for case in single_frame_normal])
#     def test_single_frame_transfer_Func(self, action, Driver, case_name, req, resp, session):
#         """
#         功能寻址单帧传输测试
#         :param action: 测试动作对象
#         :param Driver: CAN驱动对象
#         :param case_name: 测试用例名称
#         :param req: 请求报文
#         :param resp: 预期响应报文
#         :param session: 会话类型(1:默认, 2:编程, 3:扩展)
#         """
#         iStep = 1
#         iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, session, iStep, False, 'UDSFun')

#     @allure.severity('critical')
#     @allure.story('功能寻址多帧传输')
#     @allure.title('{case_name} - 功能寻址')
#     @allure.description('验证功能寻址模式下多帧数据传输功能，包括长请求和长响应处理')
#     @pytest.mark.parametrize('case_name, req, resp, session', transport_multi_frame, 
#                             ids=[case[0] for case in transport_multi_frame])
#     def test_multi_frame_transfer_Func(self, action, Driver, case_name, req, resp, session):
#         """
#         功能寻址多帧传输测试
#         :param action: 测试动作对象
#         :param Driver: CAN驱动对象
#         :param case_name: 测试用例名称
#         :param req: 请求报文
#         :param resp: 预期响应报文
#         :param session: 会话类型(1:默认, 2:编程, 3:扩展)
#         """
#         iStep = 1
#         # 设置较长的超时时间(多帧传输需要)
#         iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, session, iStep, False, 'UDSFun', timeout=2000)

#     @allure.severity('normal')
#     @allure.story('功能寻址流控参数')
#     @allure.title('{case_name} - 功能寻址')
#     @allure.description('验证功能寻址模式下流控参数(FS/BS/STmin)的配置和响应')
#     @pytest.mark.parametrize('case_name, req, resp, session', flow_control_tests, 
#                             ids=[case[0] for case in flow_control_tests])
#     def test_flow_control_parameters_Func(self, action, Driver, case_name, req, resp, session):
#         """
#         功能寻址流控参数测试
#         :param action: 测试动作对象
#         :param Driver: CAN驱动对象
#         :param case_name: 测试用例名称
#         :param req: 请求报文
#         :param resp: 预期响应报文
#         :param session: 会话类型(1:默认, 2:编程, 3:扩展)
#         """
#         iStep = 1
#         iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, session, iStep, False, 'UDSFun')